using System;
using System.Collections;
using System.Collections.Generic;
using com.youzu.warh.protocol;
using UnityEngine;
using UnityEngine.Rendering;
using Yoozoo.Gameplay.Liberty.Pool;
using Yoozoo.Gta.Common;
using Yoozoo.Mars.Got;
using Random = UnityEngine.Random;

namespace Yoozoo.Gameplay.Liberty
{
    [Serializable]
    public class TreasureBoxData
    {
        // 宝箱ID
        public int boxId;
        // 宝箱形象资源ID
        public int resID;
        // 交互cd
        public float cd;
        // 触发半径
        public float triggerRadius;
        // 洒落半径r1
        public float sprinkleRadius;
        // 洒落规避半径r2
        public float spillAvoidanceRadius;

        public TreasureBoxData(int boxId, int resID, float cd, float triggerRadius, float sprinkleRadius,
            float spillAvoidanceRadius)
        {
            this.boxId = boxId;
            this.resID = resID;
            this.cd = cd;
            this.triggerRadius = triggerRadius;
            this.sprinkleRadius = sprinkleRadius;
            this.spillAvoidanceRadius = spillAvoidanceRadius;
        }
    }
    
    /// <summary>
    /// 宝箱
    /// </summary>
    public class TreasureBox : MonoBehaviour
    {
        
        // /// <summary>
        // /// 创建宝箱
        // /// </summary>
        // /// <param name="itemId"></param>
        // /// <param name="quality"></param>
        // /// <param name="count"></param>
        // /// <returns></returns>
        // public static TreasureBox CreateTreasureBox(int boxId)
        // {
        //     bool canCreate = ResidentHandler.Inst.GetFunction("CityLuaFunction.canCreateLibertyTreasureBox").Func<int, bool>(boxId);
        //
        //     if (canCreate)
        //     {
        //         TreasureBoxData treasureBoxData = ResidentHandler.Inst.GetFunction("CityLuaFunction.getLibertyTreasureBoxData").Func<int, TreasureBoxData>(boxId);
        //         Transform boxTransform = LibertyPoolMgr.GetInstance().GetEffectObject(treasureBoxData.resID);
        //         boxTransform.gameObject.SetActive(true);
        //         TreasureBox treasureBox = boxTransform.GetComponent<TreasureBox>();
        //         treasureBox.SetData(treasureBoxData);
        //     
        //         return treasureBox;
        //     }
        //
        //     return null;
        // }
        //
        // /// <summary>
        // /// 删除宝箱
        // /// </summary>
        // /// <param name="itemId"></param>
        // /// <param name="quality"></param>
        // /// <param name="count"></param>
        // /// <param name="propItem"></param>
        // public static void DestroyTreasureBox(TreasureBox treasureBox)
        // {
        //     if (treasureBox._hasBeenDestroyed)
        //     {
        //         return;
        //     }
        //     
        //     treasureBox.Recycle();
        //     
        //     LibertyPoolMgr.GetInstance().RecycleEffect(treasureBox._treasureBoxData.resID, treasureBox.transform);
        // }
        //
        // [SerializeField]
        // private SphereCollider _collider;
        // [SerializeField]
        // private Animation _animation;
        // [SerializeField]
        // private string _closeAnimationName;
        // [SerializeField]
        // private string _openAnimationName;
        //
        // // Data
        // [SerializeField]
        // private int _boxId;
        // public int boxId => _boxId;
        // [SerializeField]
        // private TreasureBoxData _treasureBoxData;
        // // 是否已被销毁
        // private bool _hasBeenDestroyed;
        //
        // /// <summary>
        // /// 设置数据
        // /// </summary>
        // /// <param name="itemId"></param>
        // /// <param name="quality"></param>
        // /// <param name="count"></param>
        // void SetData(TreasureBoxData treasureBoxData)
        // {
        //     this._hasBeenDestroyed = false;
        //     this._boxId = treasureBoxData.boxId;
        //     this._treasureBoxData = treasureBoxData;
        //
        //     // 修改触发半径
        //     _collider.radius = this._treasureBoxData.triggerRadius;
        //     // 关闭宝箱
        //     _animation.Play(_closeAnimationName);
        // }
        //
        // /// <summary>
        // /// 玩家开启宝箱
        // /// </summary>
        // public void PlayerOpen(int[][] dropList)
        // {
        //     // 开启宝箱
        //     _animation.Play(_openAnimationName);
        //     
        //     // 掉落道具
        //     Timers.inst.StartCoroutine(showDropItems(dropList, transform.position));
        // }
        //
        // /// <summary>
        // /// 回收宝箱
        // /// </summary>
        // public void Recycle()
        // {
        //     this._hasBeenDestroyed = true;
        // }
        //
        // IEnumerator showDropItems(int[][] dropList, Vector3 dropPosition)
        // {
        //     yield return PropItem.k_PropDropInterval;
        //
        //     List<PropItem> allPropItems = ListPool<PropItem>.Get();
        //     allPropItems.Clear();
        //     for (int i = 0; i < dropList.Length; ++i)
        //     {
        //         bool isInHangingScene = ResidentHandler.Inst.GetFunction("CityLuaFunction.isInHangingScene").Func<object, bool>(null);
        //         if (!isInHangingScene)
        //         {
        //             ListPool<PropItem>.Release(allPropItems);
        //             yield break;
        //         }
        //         
        //         PropItem propItem = PropItem.CreatePropItem(dropList[i][0], dropList[i][1], dropList[i][2], false);
        //         // 随机位置
        //         float radius = Random.Range(_treasureBoxData.sprinkleRadius, _treasureBoxData.spillAvoidanceRadius);
        //         float angle = Random.Range(0, 3.1415926f*2);
        //         propItem.transform.position = dropPosition + new Vector3((float)Math.Sin(angle)*radius, 0, (float)Math.Cos(angle)*radius);
        //         allPropItems.Add(propItem);
        //         
        //         yield return PropItem.k_PropDropInterval;
        //     }
        //     
        //     // 展示掉落的道具
        //     yield return PropItem.k_PropExhibitionDuration;
        //     // 道具全部掉落完，才可以拾取
        //     foreach (var propItem in allPropItems)
        //     {
        //         propItem.OpenCollider();
        //     }
        //     ListPool<PropItem>.Release(allPropItems);
        //
        //     // 干掉宝箱
        //     TreasureBox.DestroyTreasureBox(this);
        // }


    }
}